<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" trimDirectiveWhitespaces="true" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<fmt:message var="title" key="courier.list.title"/>
<my:layout title="${title}">
 <jsp:attribute name="body">

        <p><fmt:message key="courier.list.allcouriers"/></p>

        <table class="basic">
            <tr>
                <th>id</th>
                <th><fmt:message key="user.login"/></th>
                <th><fmt:message key="user.name"/></th>
                <th><fmt:message key="user.surname"/></th>
                <th><fmt:message key="user.email"/></th>
                <th><fmt:message key="user.phone"/></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
            <c:forEach items="${couriers}" var="courier">
                <tr>
                    <td>${courier.id}</td>
                    <td><c:out value="${courier.login}"/></td>
                    <td><c:out value="${courier.contact.name}"/></td>
                    <td><c:out value="${courier.contact.surname}"/></td>
                    <td><c:out value="${courier.contact.email}"/></td>
                    <td><c:out value="${courier.contact.phone}"/></td>
                   
                    <td>
                      <form method="get" action="${pageContext.request.contextPath}/courier/deliveries/${courier.id}">
                            <input type="submit" value="<fmt:message key='user.list.deliv'/>">
                        </form>
                    </td>
                    <sec:authorize access="hasAnyRole('ROLE_ADMIN')">
                    <td>
                        <form method="post" action="${pageContext.request.contextPath}/courier/delete/${courier.id}">
                            <input type="submit" value="<fmt:message key='user.list.delete'/>">
                        </form>
                    </td>
                    <td>
                        <form method="get" action="${pageContext.request.contextPath}/account/update/${courier.login}">
                            <input type="submit" value="<fmt:message key='account.account'/>">
                        </form>
                    </td>
                     </sec:authorize>
                </tr>
            </c:forEach>
        </table>
     <sec:authorize access="hasAnyRole('ROLE_ADMIN')">
  <form:form method="post" action="${pageContext.request.contextPath}/courier/update" modelAttribute="courier">
    <fieldset><legend><fmt:message key="courier.list.titleNew"/></legend>
    <%@include file="form.jsp"%>
    <input type="submit" value="<fmt:message key='courier.list.createcourier'/>">
    </fieldset>
</form:form>
</sec:authorize>
</jsp:attribute>
</my:layout>
